﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Vkontakte.Api.Operations
{
	[ApiMethod("audio.get")]
	public sealed class AudioGet
		: Base30ApiOperation
	{
		private List<long> _audioIDs=new List<long>();

		private AudioRecord[] _audioRecords;

		protected override void Compile()
		{
			AddParameter("method", "audio.get");
			if (UserID!=null)
			{
				AddParameter("uid", UserID.Value.ToString());
			}
			if (GroupID!=null)
			{
				AddParameter( "gid", GroupID.Value.ToString() );
			}
			if (_audioIDs.Count>0)
			{
				string param = _audioIDs[ 0 ].ToString();
				for (int i=1;i<_audioIDs.Count;i++)
				{
					param += "," + _audioIDs[ i ];
				}
				AddParameter( "aids", param );
			}
			if (NeedUser)
			{
				AddParameter( "need_user", "1" );
			}
			base.Compile();
		}

		protected override void ParseData(string data)
		{
			ListingResponce responce = Serializer.LoadObjectXmlString<ListingResponce>( data );
			_audioRecords = responce.AudioRecords;
			base.ParseData(data);
		}

		public long? UserID
		{
			get; set;
		}

		public long? GroupID
		{
			get; set;
		}

		public IList<long> AudioIDs
		{
			get { return _audioIDs; }
		}

		public bool NeedUser
		{
			get; set;
		}

		public AudioRecord[] GetResult()
		{
			return _audioRecords;
		}
	}
}
